//
//  RoomListViewCell.m
//  Charles
//
//  Created by Charles on 2018/5/13.
//  Copyright © 2018年 charles. All rights reserved.
//

#import "RoomListViewCell.h"
#import "CLCollectionView.h"
#import "CLCollectionViewController.h"
#import "CLCollectionViewFlowLayout.h"
@implementation RoomListViewCell {
    CLCollectionView *_collectionView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpView];
    }
    return self;
}

- (void)setUpView {
    CLCollectionViewPageFlowLayOut *layOut = [[CLCollectionViewPageFlowLayOut alloc]init];
    layOut.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    CGFloat width = self.bounds.size.width - 30;
    layOut.itemSize = CGSizeMake(width - 50, 180);
    layOut.minimumInteritemSpacing = 0.01f;
    
    _collectionView = [[CLCollectionView alloc]initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH, 180) collectionViewLayout:layOut];
    [_collectionView setDataSource:self];
    [_collectionView setDelegate:self];
    [_collectionView setCollectionviewTag:100];
    [self addSubview:_collectionView];
    [_collectionView registerClass:[RoomListCollectionCell class] forCellWithReuseIdentifier:@"RoomListCollectionCell_Cell"];
    _collectionView.backgroundColor = [UIColor clearColor];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 5;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    RoomListCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RoomListCollectionCell_Cell" forIndexPath:indexPath];
    NSString *imageName = [NSString stringWithFormat:@"Airbnb0%ld",indexPath.row];
    cell.converImageView.image = [UIImage imageNamed:imageName];
    cell.converImageView.tag = 100000;
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"index is %@",indexPath);
    if (self.selectBlock) {
        self.selectBlock(indexPath, collectionView, self);
    }
}

@end

@implementation RoomListCollectionCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpView];
    }
    return self;
}

- (void)setUpView {
    self.converImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height - 44)];
    [self.contentView addSubview:self.converImageView];

    self.descImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.converImageView.frame) - 10, self.bounds.size.width, 44)];
    self.descImageView.image = [UIImage imageNamed:@"AirbnbPrice"];
    [self.contentView addSubview:self.descImageView];
    self.descImageView.contentMode = UIViewContentModeScaleAspectFit;

}

@end
